package com.tm.chargecar.service.impl;

import com.tm.chargecar.entity.ElectronicCardEntity;
import com.tm.chargecar.mapper.ElectronicCardMapper;
import com.tm.chargecar.result.Result;
import com.tm.chargecar.service.ElectronicCardService;
import com.tm.chargecar.utils.PageUtil;
import com.tm.chargecar.vo.ElectronicCardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 该死了
 * @create 2022-08-24 9:40
 */
@Service
public class ElectronicCardServiceImpl implements ElectronicCardService {
    @Autowired
    private ElectronicCardMapper electronicCardMapper;
    //普通查询以及条件查询
    @Override
    public Result electronicCardQuery(ElectronicCardVo electronicCardVo) {
         //返回总条数
        Long total=electronicCardMapper.electronicCardTotal(electronicCardVo);
        //把总条数放入分页的工具包
        PageUtil pageUtil=new PageUtil();
        pageUtil.setTotalCount(total);
        //根据条件查出相对应的数据
        List<ElectronicCardEntity> list=electronicCardMapper.electronicCardQuery(electronicCardVo);
        pageUtil.setData(list);
        return Result.SUCCESS(pageUtil);
    }
    //新增电子卡类型
    @Override
    public Result electronicCardAdd(ElectronicCardEntity electronicCardEntity) {
        //给卡类型创建时间赋值
        electronicCardEntity.setCreateDate(System.currentTimeMillis());
        //给卡类型赋固定话述
        electronicCardEntity.setCardWarning("使用须知，为固定话术：\n" +
                "1. 本卡仅供用户充电支付时使用，具体使用规则以购买卡片时页面显示为准；\n" +
                "2. 扫码或刷卡充电均可使用本卡片，若用户同时有套餐卡和储值卡，系统默认推荐使用套餐卡；\n" +
                "3. 本卡由各站点运营商发行，有任何疑问可拨打站点服务电话进行咨询。");
        //给卡类型卡产品编号赋值
        electronicCardEntity.setCardId(System.currentTimeMillis());
        //进行新增
        electronicCardMapper.electronicCardAdd(electronicCardEntity);
        return Result.SUCCESS();
    }


}
